/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uloha3;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import uloha1.Riesenie;

public class Run {

    public static void main(String[] args) {
        

        if (args.length != 2) {
            System.out.println("Zle vstupne parametre, ocakavane su 2");
            System.out.println("Param 1 . sposob vypoctu (-Dynamicky , -BandB, -MaxVec)");
            System.err.println("Program konci, nespravne vstupne parametre");
            System.exit(2);
        }

        
        String algoritmus = args[0];
        String vstupnySubor = args[1];
        
        BatohAlgoritmus alg;
         String riesenie = "";
        DataParser vstupneData = new DataParser(vstupnySubor);
        List<Batoh> zoznamInstancii = vstupneData.nacitajVstupnySuborSInstanciou();

        
        if ((new String("-Dynamicky")).equalsIgnoreCase(algoritmus)) {
            System.out.println("Riesenie Dynamicky");
            alg = new VyriesDynamicky(zoznamInstancii);
            long start = System.nanoTime();
            riesenie = alg.vyriesProblemBatohu();
            long end = System.nanoTime();
            System.out.println("Cas na vyriesenie batohu pomocou dynamickeho programovania je " +((double)(end- start)/1000000.0));
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            //DataComparator statistiky = new DataComparator("sol"+File.separator+vstupnySubor.substring(4,vstupnySubor.length()), "temp.txt");
            //statistiky.zistiStatistiky();
            
        } else if ((new String("-BandB")).equalsIgnoreCase(algoritmus)) {
            System.out.println("Riesenie BandB");
            
            alg = new VyriesBandB(zoznamInstancii);
            long start = System.nanoTime();
            //long start = System.currentTimeMillis();
            riesenie = alg.vyriesProblemBatohu();
            long end = System.nanoTime();
            //long end = System.currentTimeMillis();
            System.out.println("Cas na vyriesenie batohu pomocou B&B je " +((double)(end- start)/1000000.0));
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            DataComparator statistiky = new DataComparator("sol"+File.separator+vstupnySubor.substring(4,vstupnySubor.length()), "temp.txt");
            statistiky.zistiStatistiky();
            
        } else if ((new String("-MaxVec2")).equalsIgnoreCase(algoritmus)) {
            System.out.println("Riesenie pridanim max veci");
            alg = new VyriesHeuristikou2(zoznamInstancii);
            riesenie = alg.vyriesProblemBatohu();
            
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            DataComparator statistiky = new DataComparator("sol"+File.separator+vstupnySubor.substring(4,vstupnySubor.length()), "temp.txt");
            statistiky.zistiStatistiky();
            
        } else if ((new String("-MaxVec3")).equalsIgnoreCase(algoritmus)) {
            System.out.println("Riesenie pridanim max veci ver2");
            alg = new VyriesHeuristikou3(zoznamInstancii);
            riesenie = alg.vyriesProblemBatohu();
            
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            DataComparator statistiky = new DataComparator("sol"+File.separator+vstupnySubor.substring(4,vstupnySubor.length()), "temp.txt");
            statistiky.zistiStatistiky();
        }
        else if ((new String("-MaxVec1")).equalsIgnoreCase(algoritmus)) {
            System.out.println("Riesenie pridanim max veci ver2");
            alg = new VyriesHeuristikou1(zoznamInstancii);
            riesenie = alg.vyriesProblemBatohu();
            
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            DataComparator statistiky = new DataComparator("sol"+File.separator+vstupnySubor.substring(4,vstupnySubor.length()), "temp.txt");
            statistiky.zistiStatistiky();
        }
        else if ((new String("-Hrubo")).equalsIgnoreCase(algoritmus))
        {
            System.out.println("Riesenie Hrubou silou");
            
            alg = new VyriesHrubouSilou(zoznamInstancii);
            long start = System.nanoTime();
            //long start = System.currentTimeMillis();
            riesenie = alg.vyriesProblemBatohu();
            long end = System.nanoTime();
            //long end = System.currentTimeMillis();
            System.out.println("Cas na vyriesenie batohu pomocou Hrubej sily je " +((double)(end- start)/1000000.0));
            DataWriter zapisSuboru = new DataWriter("temp.txt", riesenie);
            zapisSuboru.zapisSubor();
            DataComparator statistiky = new DataComparator("sol"+File.separator+"knap_4.sol.dat", "temp.txt");
            statistiky.zistiStatistiky();
            
        }
        
        
    } // koniec main


}
